package cn.coisini.controller.v1;

import cn.coisini.api.search.SearchControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.dto.UserSearchDto;
import cn.coisini.model.pojo.UserSearch;
import cn.coisini.service.UserSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 搜索控制层
 */
@RestController
@RequiredArgsConstructor
public class SearchController implements SearchControllerApi {

    private final UserSearchService userSearchService;

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索管理", businessType = BusinessType.SELECT)
    public Result<List<UserSearch>> getUserSearch(UserSearchDto userSearchDto) {
        return userSearchService.getUserSearch(userSearchDto);
    }

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> delUserSearch(UserSearchDto userSearchDto) {
        return userSearchService.delUserSearch(userSearchDto);
    }

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索管理", businessType = BusinessType.INSERT)
    public void addUserSearch(@RequestBody UserSearchDto userSearchDto) {
        userSearchService.addUserSearch(userSearchDto);
    }

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索管理", businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> delUserSearchAll() {
        return userSearchService.delUserSearchAll();
    }
}
